<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- 使用组件 -->
        <chat></chat>
        <chat></chat>



    </div>
</body>

</html>
<script src="./js/vue.js"></script>
<script>
    // 2、定义一个子组件
    let commonmsg = {
        template: `
            <div>
                <ul>
                    <li>
                        <input type="radio" >在干嘛        
                    </li>
                    <li>
                        <input type="radio" >吃了吗
                    </li>
                    <li>
                        <input type="radio" >睡了吗
                    </li>
                    <li>
                        <input type="radio" >收到
                    </li>
                </ul>
            </div>
        `
    }

    // 1、定义一个父组件
    let chat = {
        template: `
            <div>
                <h3>{{className}}的聊天室</h3>
                <div style="width:200px;height:300px;border:1px solid red" v-html="allmsg"></div>
                <input type="text" v-model="msg" />
                <input type="button" value="发送" @click="sendMsg" />
                <hr/>
                <commonmsg></commonmsg>
            </div>
        `,
        components: {
            "commonmsg": commonmsg
        },
        data() {
            return {
                className: "2212",
                allmsg: "",
                msg: ""
            }
        },
        methods: {
            sendMsg() {
                this.allmsg += this.msg + "<br/>";
                this.msg = "";
            }
        }
    }



    let vm = new Vue({
        el: "#app",
        // template:`
        //     <div>
        //         vue根对象的模板
        //     </div>
        // `,
        data:{
            msg:"hello"
        },
        // 局部注册
        components: {
            "chat": chat
        }
    });


</script>